home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_47916.txt < prev    next >
Text File  |  1991-02-27  |  957b  |  21 lines

  1. -- card: 47916 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. pointer.  For example, suppose the Student class is derived from the Person class, yet contains a member function set_roommate() which is not inherited from the Person class.  Then if a Person pointer is assigned the address of a student object a cast must be made so the pointer may be treated as a Student pointer:
  11.  
  12.     Person    *guy;
  13.     guy = new(Student);
  14.     guy->init(); 
  15.     ((Student*) guy)->set_roommate();
  16.  
  17. Notice that no cast is needed in order to send the init() message to guy, since the Person class contains an init() member function.  If the Student class overrides this member function, it is the Student's member function which will be invoked.  (In C++ it is necessary to declare init() as a 'virtual' member function.)
  18.  
  19. -- part contents for background part 7
  20. ----- text -----
  21. 151